import { toSuccess, useEntityManager } from "@sker/core";
import { AutoUser } from "@sker/entities";
import { useData } from "@sker/runtime";
import { z } from "zod";


export default async () => {
    const input = z.object({
        token: z.optional(z.string()),
    });
    const body = input.parse(useData())
    if (!body.token) {
        return toSuccess(false)
    }
    return await useEntityManager(async m => {
        const user = await m.findOne(AutoUser, { where: { token: body.token } })
        if (!user) return toSuccess(false)
        return toSuccess({ setting: user.setting || { minTime: 60, maxTime: 60 * 1.5, status: `start` } })
    })
}
